/*
 * Scott Franks & Anthony Roy
 * CS 474 - Project 3
 * Cupcakes 7
 *
 */

#include <iostream>      // for C++ I/O
#include <cctype>        // for case conversion using toupper() and tolower()
#include <cstring>       // for string functions, e.g. strrchr
using namespace std;     
#include<fstream>
//------------------------------------------------------------------ 
// Global constants  


void displayIdentifyingInformation()
{
   cout << "Author: Scott Franks & Anthony Roy\n" 
        << "Program 3: Cupcakes7 \n" 
        << "April 29, 2011 \n" 
        << endl;       
}//end displayIdentifyingInformation()


//------------------------------------------------------------------ 

void displayInstructions()
{
    cout << "Welcome to Cupcakes7! \n" 
         << " \n" 
         << "Cupcakes 7 will help people in preparing meals. In order to perform this \n"
         << "function, Cupcakes 7 must know about recipes and their ingredients, and also \n"
         << "about foods available in the user\'s refrigerator and cupboards. Users will \n"
         << "generally enter meal requests, which might consist of an appetizer, a main \n"
         << "dish, a side dish and a dessert. Subsequently Cupcakes 7 will check both the \n"
         << "recipes of the dishes entered by the user and the ingredients available in \n"
         << "the user\'s refrigerator and cupboards. Finally, the Cupcakes 7 will \n"
         << "automatically generate a grocery list of the missing ingredients. will supply a\n"
         << "list of dishes that can be prepared with foods currently available at the user\'s"
         << "home. User queries may be broadly divided into the following categories: \n" 
         << "Appetizers, main dishes, side dishes, and desserts. After a user selects a dish,"
         << "Cupcakes 7 follows up with a set of detailed instructions on how to cook the\n"
         << "dish. Finally, Cupcakes 7 updates its own information by removing the"
         << "ingredients used in the preparation of the dish from the available foods. \n"
         << endl;     
            
}// end displayInstructions()
   

//------------------------------------------------------------------ 

void recipeLoader() {

    char buffer[300];
    ifstream myfile ("recipeList.txt");
    int counter=0;
    
    while (! myfile.eof() ) {
    	myfile.getline (buffer,100);
    	counter++;
    }
            
    char recepies[counter][256];   
     
    int lineC =0;
    char buffer2[300];
    ifstream myfile2 ("recipeList.txt");
    
    while (! myfile2.eof() ){
    	myfile2.getline (buffer,100);
    	strcpy(recepies[lineC],buffer);
    	lineC++;
    }
    cout<< recepies[1];

}

//------------------------------------------------------------------ 
void help(){
     
         cout << "Welcome to Cupcakes7! \n" 
         << " You are given the options (by selection number): \n" 
         << " 1. Edit, Add or Delete recipes \n"
         << " 2. Add, delete items from Inventory \n"
         << " 3. Construct a meal of 4 parts: Appetizers, Main Dishes,\n Side Dishes and Desserts.   \n"
         << endl; 

}// end help()


//------------------------------------------------------------------ 
// the order menu control flow
void ordMenu(){ 
    int oChoice; //user input
    bool oExit; // exit? yes, no
    int menuCounter = 0; // how many items to loop for menu selection
    //int cMenu = 1;
        
    char dishes[3][50]; // 4 element array of char string

    // the dish options
    strcpy(dishes[0],"Appetizers \n");
    strcpy(dishes[1],"Main Dishes \n");
    strcpy(dishes[2],"Side Dishes \n");
    strcpy(dishes[3],"Desserts \n");
    
    // while exit has not been slected and not more then 4 items have been choosen
    while ( oExit != 1 && (menuCounter < 4))
    {  
        cout << "\n Select menu item if desired: \n" 
            << ("1. ")
            << ("%s", dishes[menuCounter]) //dish number from dishes array
            << "2. Continue Without \n"
            << "3. Go Back to Main \n"
            << endl;

        cin>>oChoice; // input
        
        // switch for user input
        switch ( oChoice ){
             case 1:
                //cout<< "Recipe Edit \n";
                //recipeLoader();
                cout << "Select from the following options: \n" ;
                menuCounter++;
                break;
              case 2:
                cout << "Continuing without "
                << ("%s", dishes[menuCounter])
                << endl;
                menuCounter++;
                break;            
             case 3:
                cout<<"Going Back \n";
                oExit=1;
                break;
             default:
                cout<<"ERROR in 2nd Switch \n";
        }
   }
    cout << "\n Returing to Main Menu \n\n";
    menuCounter = 0;
    oExit = 0;
}// end ordMenu()


//------------------------------------------------------------------ 
void menu(){
    int mChoice;
    bool mExit;
    while ( mExit != 1 )
    {  
        cout << "Main Menu \n Select from the following options by entering a number selction: \n" 
            << "1. Recipe Edit \n" 
            << "2. Ingredient Inventory \n" 
            << "3. Order Menu \n"
            << "4. Help \n"
            << "5. Exit \n"
            << endl;
        cin>>mChoice;
        switch ( mChoice ){
             case 1:
                cout<< "\n Recipe Edit \n";
                break;
             case 2:
                cout<<" \n Ingredient Inventory \n";
                break;
             case 3:
                cout<<"\n Order Menu \n";
                ordMenu();
                break;
             case 4:
                cout<<" \n Help \n";
                help();
                break;
             case 5:
                cout<<" \n Exiting.... \n";
                mExit=1;
                break;
             default:
                cout<<"ERROR in 1st Switch \n";
        }
        
   }

}// end menu()

               
//------------------------------------------------------------------ 
// main()
//    Starting point for program.

int main()
{    
    // Display identifying information
    // displayIdentifyingInformation();
    
    // Display instructions
    // displayInstructions();
    
    recipeLoader();
    
    // main menu system
    menu();
    //exit(1);
    
}//end main()
